﻿namespace PlaylistCopy.Helpers
{
    using System;
    using System.Windows;
    using System.Windows.Threading;

    internal static class DispatcherHelper
    {
        public static Dispatcher UiDispatcher
        {
            get;
            private set;
        }

        public static void SafeDispatch(Action action)
        {
            if (UiDispatcher.CheckAccess())
            {
                action();
            }
            else
            {
                UiDispatcher.BeginInvoke(action);
            }
        }

        public static void Initialize()
        {
            if (UiDispatcher != null)
            {
                return;
            }

            UiDispatcher = Application.Current.Dispatcher;
        }
    }
}
